Improve handling of bogus NMEA.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 21 Feb 2011 16:55:33 +0000 (16:55 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 21 Feb 2011 16:55:33 +0000 (16:55 +0000)
gpsbabel/nmea.c

index df3da62bdb97e86c37aea8b31ca54e9771547e7d..a3bac09b5c7b8bc1f3bf0d004a424d6af0237678 100644 (file)
@@ -532,8 +532,12 @@ gprmc_parse(char *ibuf)
        }
 
        /* Skip past nine commas in ibuf to reach the dmy value */
-       for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) {
+       for (dmybuf=ibuf,i=0; i<9; i++) {
                dmybuf= strchr(dmybuf, ',');
+               if(dmybuf==NULL) {
+                       /* If we run out of commas, the sentence is invalid. */
+                       return;
+               }
                dmybuf++;
        }
 
@@ -910,6 +914,12 @@ nmea_parse_one_line(char *ibuf)
                had_checksum = 0;
                return;
        }
+       
+       if(strstr(tbuf+1,"$")!=NULL)
+       {
+               /* If line has more than one $, there is probably an error in it. */
+               return;
+       }
 
        /* @@@ zmarties: The parse routines all assume all fields are present, but 
           the NMEA format allows any field to be missed out if there is no data